<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改请假记录')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-leave-edit" th:object="${recordLeave}">
            <input name="leaveId" th:field="*{leaveId}" type="hidden">
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">人员类型：</label>
                <div class="col-sm-8">
                    <select name="userType" id="userType" class="form-control m-b">
                        <option value="01" th:selected="*{userType == '01'}">普通职工</option>
                        <option value="02" th:selected="*{userType == '02'}">中层及以上</option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">代理人：</label>
                <div class="col-sm-8">
                    <input id="agentUser" name="agentUser" class="form-control" type="text" th:field="*{agentUser}">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">休假类型：</label>
                <div class="col-sm-8">
                    <select name="leaveType" class="form-control m-b" th:with="type=${@dict.getType('record_leave_type')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{leaveType}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">请假事由：</label>
                <div class="col-sm-8">
                    <textarea name="remark" class="form-control">[[*{remark}]]</textarea>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">开始时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="startTime" id="startTime" th:value="${#dates.format(recordLeave.startTime, 'yyyy-MM-dd')}" class="form-control" placeholder="yyyy-MM-dd" type="text" required>
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">结束时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="endTime" id="endTime" th:value="${#dates.format(recordLeave.endTime, 'yyyy-MM-dd')}" class="form-control" placeholder="yyyy-MM-dd" type="text" required>
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">天数：</label>
                <div class="col-sm-8">
                    <input name="days" th:field="*{days}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <textarea name="remark" class="form-control">[[*{remark}]]</textarea>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script th:inline="javascript">
        var prefix = ctx + "record/leave";
        $("#form-leave-edit").validate({
            focusCleanup: true
        });

        changeType();

        function changeType() {
            var userType = $("#userType").val();
            if(userType == '01'){
                $("#agentUser").parents(".form-group").hide();
            }else{
                $("#agentUser").parents(".form-group").show();
            }
        }

        function changeDays() {
            var startTime = $("#startTime").val();
            var endTime = $("#endTime").val();
            if(startTime != '' && endTime != ''){
                var days = (Date.parse(endTime) - Date.parse(startTime)) / (24 * 60 * 60 * 1000);
                $("#days").val(days + 1);
            }
        }

        /* 选择人员 */
        function selectUserTree() {
            var options = {
                title: '选择代理人',
                width: "380",
                url: ctx + "basic/user/selectTree",
                callBack: doSubmit
            };
            $.modal.openOptions(options);
        }

        function doSubmit(index, layero){
            var body = layer.getChildFrame('body', index);
            $("#treeId").val(body.find('#treeId').val());
            $("#treeName").val(body.find('#treeName').val());
            layer.close(index);
        }

        function submitHandler() {
            var userType = $("#userType").val();
            var agendId = $("#treeId").val();
            if(userType == '02' && agendId == ''){
                $.modal.alertError("请选择代理人");
                return;
            }
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-leave-edit').serialize());
            }
        }

        $("input[name='startTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            max: $('#endTime').val(),
            autoclose: true
        });

        $("input[name='endTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            min: $('#startTime').val(),
            autoclose: true
        });
    </script>
</body>
</html>